﻿<%@ Page Title="" Language="C#" AutoEventWireup="false" CodeFile="recRegistrationStatusUpdate.aspx.cs"
    Inherits="SIPO.Web.Forms.Transaction.recRegistrationStatusUpdate" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Update Status Registrasi</title>

    <script src="<%= ResolveUrl("~/scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.wrapper.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.inputmask.bundle.min.js") %>" type="text/javascript"></script>
     
    <script type="text/javascript">

        $(document).ready(function () {

            $("#btnCancel").button({ icons: { primary: "ui-icon-close"} });
            $("#btnSave").button({ icons: { primary: "ui-icon-disk"} });

            $('#btnCancel').click(function () {
                parent.$('#dialog1').dialog('close');

            });      

        });

    </script>

    <script type="text/javascript">

        $(document).ready(function () {

            var today = new Date();
            var dd = today.getDate() + 1;
            var mm = today.getMonth() + 1; //January is 0!

            GetInvoiceValue();

            $("#txtPaymentValue").inputmask("decimal", { radixPoint: ",", autoGroup: true, groupSeparator: ".", groupSize: 3, digits: 2, repeat: 18 });

            $("#txtPaymentNo").inputmask("Regex", { regex: "[A-Za-z-.0-9 ]*" });

            var yyyy = today.getFullYear();
            if (dd < 10) { dd = '0' + dd } if (mm < 10) { mm = '0' + mm } today = mm + '/' + dd + '/' + yyyy;

            $("#txtPaymentDate").datepicker({ showWeek: true, showButtonPanel: true,
                changeMonth: true, changeYear: true, dateFormat: 'dd/mm/yy', // yearRange: '1990:2030'
                maxDate: 0
            });

            // 1. prepare the validation rules and messages.
            var rules = {
                ddlRegistrationStatus: "required",
                txtPaymentNo: {
                    required: true,
                    maxlength: 10
                },
                txtPaymentValue: "required",
                txtPaymentDate: "required"
            };
            var messages = {
                ddlRegistrationStatus: "Status Registrasi wajib di isi",
                txtPaymentNo: {
                    required: "No Pembayaran wajib di isi",
                    maxlength: "Panjang maksimal No.Pembayaran adalah 10"
                },
                txtPaymentValue: "Jumlah Pembayaran wajib di isi",
                txtPaymentDate: "Tanggal Pembayaran wajib di isi"
            };

            // 2. Initiate the validator
            var validator = new jQueryValidatorWrapper("form1", rules, messages);

            function GetInvoiceValue() {
                var invoiceno = '<%= Request.Params["invoiceno"] %>';
                var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/getinvoicevalue.ashx?invoiceno=' + invoiceno + '") %>';
                if (invoiceno != "") {
                    jQuery.ajax({
                        type: 'POST',
                        url: handlerUrl,
                        contentType: 'application/json',
                        dataType: 'json',
                        success: function (data) {
                            if (data.InvoiceValue != 0) {

                                // var unformatvalue = accounting.unformat(parseFloat(data.InvoiceValue), ",", "."); // Revert to en-US format
                                // $('#txtPaymentValue').val(accounting.formatNumber(unformatvalue, 2, ".", ",")); // Set to id-ID format
                                // $('#txtPaymentValue').val(data.InvoiceValue); // Set to id-ID format

                                var unformatvalue = parseFloat(data.InvoiceValue);
                                $('#txtPaymentValue').val(unformatvalue.formatMoney(2, ".", ",")); // Set to id-ID format

                            }
                        },
                        error: function () {
                            alert('Error!');
                        }
                    });
                }
            }

            // 3. Set the click event to do the validation
            $("#btnSave").click(function () {

                if (!validator.validate())
                    return;

                var paymentNo = $('#txtPaymentNo').val();
                var paymentValue = $('#txtPaymentValue').val();
                var registrationstatus = $("#ddlRegistrationStatus option:selected").val();
                var paymentdate = $('#txtPaymentDate').val();
                var id = $('#<%= hfID.ClientID %>').val();
                var invoiceno = $('#<%= hfInvoiceNo.ClientID %>').val();
                var sectorregistrationid = $('#<%= hfSectorRegistrationID.ClientID %>').val();
                var registrationstatusvalue = $("#ddlRegistrationStatus option:selected").text();

                var obj = new Object();
                obj.PaymentNo = encodeURIComponent(paymentNo);
                obj.PaymentValue = encodeURIComponent(paymentValue);
                obj.PaymentDate = encodeURIComponent(paymentdate);
                obj.RegistrationStatusID = encodeURIComponent(registrationstatus);
                obj.RegistrationID = id;
                obj.InvoiceNo = invoiceno;
                obj.SectorRegistrationID = sectorregistrationid;
                obj.RegistrationStatusValue = encodeURIComponent(registrationstatusvalue);

                jsonData = JSON.stringify(obj);

                var handlerUrl = '<%= ResolveUrl("~/ajaxhandler/transaction/recRegistrationhandler.ashx") %>';

                CallAjax(handlerUrl, "?method=updatestatusregistration", jsonData);

                parent.$('#dialog1').dialog('close');
                $("#txtPaymentDate").datepicker("destroy");

                setTimeout("parent.$('#table').trigger('reloadGrid');", 3000);

                return false;
            });


        });
    
    </script>
    <script type="text/javascript">

        function ClearText() {
            $('#txtPaymentNo').val('');
            $('#txtPaymentValue').val('');
        }

        $(".ui-dialog-titlebar-close").click(function () {
            //debugger;
            $("#txtPaymentDate").datepicker("destroy");
        });
        
         
    </script>
</head>
<body onload="ClearText();">
    <form id="form1" runat="server">
    <table border="0">
        <tr runat="server" visible="false">
            <td style="width: 50">
                Nomor Pembayaran
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtPaymentNo" MaxLength="13" runat="server" Width="200" Enabled="False"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td style="width: 50">
                Tanggal Pembayaran
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtPaymentDate" runat="server" Width="200"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td style="width: 50">
                Jumlah Pembayaran
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtPaymentValue" runat="server" Width="200" MaxLength="100"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td style="width: 50">
                Status Registrasi Sekarang
            </td>
            <td>
                :
            </td>
            <td>
                <asp:Label ID="lblStatusRegistrasi" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td style="width: 50">
                Status Registrasi
            </td>
            <td>
                :
            </td>
            <td>
                <asp:DropDownList ID="ddlRegistrationStatus" runat="server" Width="200">
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                &nbsp;
            </td>
            <td>
                <div style="text-align: right; padding-top: 10px;">
                    <button id="btnSave" type="button">Simpan</button>
                    <button id="btnCancel" type="button">Batal</button>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                &nbsp;
            </td>
            <td>
                <asp:HiddenField ID="hfID" runat="server" />
                <asp:HiddenField ID="hfInvoiceNo" runat="server" />
                <asp:HiddenField ID="hfSectorRegistrationID" runat="server" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
